package com.ruoyi.web.controller.Base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.AbilitySubscribe;
import com.ruoyi.service.Ability_SubscribeInforService;
import com.ruoyi.service.IAbilitySubscribeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户订阅Controller
 * 
 * @author ruoyi
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/web/subscribe")
public class AbilitySubscribeController extends BaseController
{
    @Autowired
    private IAbilitySubscribeService abilitySubscribeService;
    @Autowired
    Ability_SubscribeInforService ability_SubscribeInforService;
    /**
     * 查询用户订阅列表
     */

    @GetMapping("/list")
    public TableDataInfo list(AbilitySubscribe abilitySubscribe)
    {
        startPage();
        List<AbilitySubscribe> list = abilitySubscribeService.selectAbilitySubscribeList(abilitySubscribe);
        return getDataTable(list);
    }

    /**
     * 导出用户订阅列表
     */

    @Log(title = "用户订阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbilitySubscribe abilitySubscribe)
    {
        List<AbilitySubscribe> list = abilitySubscribeService.selectAbilitySubscribeList(abilitySubscribe);
        ExcelUtil<AbilitySubscribe> util = new ExcelUtil<AbilitySubscribe>(AbilitySubscribe.class);
        util.exportExcel(response, list, "用户订阅数据");
    }

    /**
     * 获取用户订阅详细信息
     */

    @GetMapping(value = "/get")
    public AjaxResult getInfo(@RequestParam(value = "ID", required = true) Long ID)
    {
        return success(abilitySubscribeService.selectAbilitySubscribeByID(ID));
    }

    /**
     * 新增用户订阅
     */

    @Log(title = "用户订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AbilitySubscribe abilitySubscribe)
    {
        return toAjax(abilitySubscribeService.insertAbilitySubscribe(abilitySubscribe));
    }

    /**
     * 修改用户订阅
     */

    @Log(title = "用户订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AbilitySubscribe abilitySubscribe)
    {
        return toAjax(abilitySubscribeService.updateAbilitySubscribe(abilitySubscribe));
    }

    /**
     * 删除用户订阅
     */

    @Log(title = "用户订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ID}")
    public AjaxResult remove(@PathVariable Integer ID )
    {
        int k=  ability_SubscribeInforService.deleteAbility_SubscribeInforById(ID);
        if(k==0){
            return AjaxResult.error("删除失败，服务器发生错误");
        }else if(k==-1){
            return  AjaxResult.error("删除失败，代理服务器发生错误");
        }else{
            return AjaxResult.success("删除成功");}
    }
}
